package com.anxin.act.busFlow.web;

import java.util.List;

import com.anxin.act.busFlow.dto.WfConfigNodeDto;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anxin.framework.aspectj.lang.annotation.Log;
import com.anxin.framework.aspectj.lang.enums.BusinessType;
import com.anxin.act.busFlow.entity.WfConfigNode;
import com.anxin.act.busFlow.service.WfConfigNodeService;
import com.anxin.framework.web.controller.BaseController;
import com.anxin.framework.web.entity.AjaxResult;
import com.anxin.common.utils.poi.ExcelUtil;
import com.anxin.framework.web.page.TableDataInfo;

/**
 * 业务流程节点Controller
 *
 * @author jbs
 * @date 2020-04-08
 */
//@Api(tags = "业务流程节点" )
@RestController
@RequestMapping("/node/wfConfigNode")
public class WfConfigNodeController extends BaseController{
    @Autowired
    private WfConfigNodeService wfConfigNodeService;

    /**
     * 查询业务流程节点列表
     */
    //@ApiOperation(value="查询业务流程节点列表" ,notes="作者:jbs")
    @PreAuthorize("@ss.hasPermi('act:busflow:view')")
    @Log(title = "查询业务流程节点列表", businessType = BusinessType.LIST)
    @GetMapping("/list")
    public TableDataInfo<List<WfConfigNode>> list(WfConfigNode wfConfigNode){
        startPage();
        List<WfConfigNode> list = wfConfigNodeService.findList(wfConfigNode);
        return getDataTable(list);
    }

    /**
     * 复制并保存选中节点
     */
    //@ApiOperation(value="复制并保存选中节点" ,notes="作者:jbs")
    @PreAuthorize("@ss.hasPermi('act:busflow:view')")
    @Log(title = "复制并保存选中节点", businessType = BusinessType.INSERT)
    @PostMapping("/saveCopyNode")
    public AjaxResult saveCopyNode(@RequestBody WfConfigNodeDto wfConfigNodeDto){
        return AjaxResult.success(wfConfigNodeService.saveCopyNode(wfConfigNodeDto));
    }

    /**
     * 导出业务流程节点列表
     */
    //@ApiOperation(value="导出业务流程节点列表",notes="作者:jbs")
    @PreAuthorize("@ss.hasPermi('act:busflow:export')")
    @Log(title = "业务流程节点", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WfConfigNode wfConfigNode) {
        List<WfConfigNode> list = wfConfigNodeService.findList(wfConfigNode);
        ExcelUtil<WfConfigNode> util = new ExcelUtil<WfConfigNode>(WfConfigNode.class);
        return util.exportExcel(list, "node");
    }

    /**
     * 获取业务流程节点详细信息
     */
    //@ApiOperation(value="获取业务流程节点详细信息",notes="作者:jbs")
//    @PreAuthorize("@ss.hasPermi('act:busflow:view')")
    @GetMapping(value = "/{id}")
    @Log(title = "获取业务流程节点详细信息", businessType = BusinessType.LIST)
    public AjaxResult<WfConfigNode> getInfo(@PathVariable("id") String id){
        return AjaxResult.success(wfConfigNodeService.getById(id));
    }

    /**
     * 保存业务流程节点
     */
    //@ApiOperation(value="保存业务流程节点",notes="作者:jbs")
    @PreAuthorize("@ss.hasPermi('act:busflow:edit')")
    @Log(title = "业务流程节点", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody WfConfigNode wfConfigNode){
        return toAjax(wfConfigNodeService.save(wfConfigNode));
    }

    /**
     * 查询parentId为0的节点
     */
    //@ApiOperation(value="查询一级节点",notes="作者:刘翔宇")
    @PreAuthorize("@ss.hasPermi('act:busflow:edit')")
    @GetMapping(value = "/parentNode/{nodeType}/{flowId}")
    public AjaxResult parentNode(@PathVariable("flowId") String flowId,@PathVariable("nodeType") String nodeType){
        WfConfigNode wfConfigNode = new WfConfigNode();
        wfConfigNode.setFlowId(flowId);
        wfConfigNode.setNodeType(nodeType);
        wfConfigNode.setParentId("0");
        List<WfConfigNode> configNodeList = wfConfigNodeService.findList(wfConfigNode);
        return AjaxResult.success(configNodeList);
    }

    /**
     * 删除业务流程节点
     */
    //@ApiOperation(value="删除业务流程节点",notes="作者:jbs")
    @PreAuthorize("@ss.hasPermi('act:busflow:remove')")
    @Log(title = "业务流程节点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable(("id")) String id){
        return toAjax(wfConfigNodeService.deleteById(id));
    }
}
